package persistence;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import configs.DBConfigs;

public class DAO {
	private static DAO dao;
	private Connection con;
	
	protected DAO(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			con = (Connection) DriverManager.getConnection(DBConfigs.URI_JDBC, DBConfigs.USER, DBConfigs.PASSWORD);
		} 
		catch(ClassNotFoundException e) {
			e.printStackTrace();
		} 
		catch(SQLException e){
			e.printStackTrace();
		}
		
	}
	
	public static DAO getInstance(){
		if(dao != null){
			return dao;
		}
		
		return new DAO();
	}
	
	public Connection getConnection(){
		return con;
	}
}
